package com.xiaozhen.config;

import cn.dev33.satoken.stp.StpInterface;
import com.xiaozhen.common.core.domain.system.SysUser;
import com.xiaozhen.system.service.SysMenuService;
import com.xiaozhen.system.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * HISTORY
 *
 * @author zhenweisheng
 * @date 2021/11/17 17:58
 * @description:
 */
@Component
public class StpInterfaceImpl implements StpInterface {

    @Autowired
    private SysMenuService sysMenuService;
    @Autowired
    private SysRoleService sysRoleService;

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        SysUser sysUser = new SysUser();
        sysUser.setUserId(Long.parseLong((String) loginId));
        Set<String> menuPermission = sysMenuService.getMenuPermission(sysUser);
        return new ArrayList<>(menuPermission);
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        SysUser sysUser = new SysUser();
        sysUser.setUserId(Long.parseLong((String) loginId));
        Set<String> rolePermission = sysRoleService.getRolePermission(sysUser);
        return new ArrayList<>(rolePermission);
    }
}
